

import React, { Component } from "react";
import Grid from '../../../../components/display/grid';
import { Form, Input, Row, Col, Button, Select, Divider, DatePicker, Upload, Switch, Icon, Tooltip, message } from 'antd';
import SaasModal from '../../../../components/display/SaasModal';
import {EVCSDetails} from '../../../../fetch/fetchApi';
const Option = Select.Option;
const FormItem = Form.Item;
const createForm = Form.create;
// const {TextArea} = Input;

class sevenModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            refresh:0,
            params:{
            },
        };
        this.columns2=[
            {
                title: '组织机构代码',
                dataIndex: 'licenceNo',
                key: 'licenceNo',
            },
            {
                title: '企业名称',
                dataIndex: 'companyName',
                key: 'companyName',
            },
            {
                title: '操作',
                key: 'sss',
                width:120,
                render: (text,record) => (
                    <span>
                        <a onClick={()=>{this.choose(text)}}>添加</a>
                    </span>
                )
            },
        ]
    }

    componentWillReceiveProps(nextProps){
        this.setState({
            params:Object.assign(this.state.params,{appkey:nextProps.appkey})
        })
    }
    componentDidMount(){
        console.log('this.props',this.props)
        this.setState({
            params:Object.assign(this.state.params,{appkey:this.props.appkey})
        })
    }
    choose=(text)=>{
        this.props.addItem(text);
    }

    getData=()=>{
        
    }


    handleSubmit =(e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, values) => {
            if (!!err) {
                return;
            }
            debugger;
            console.log(values);
            this.setState({
                params:Object.assign(this.state.params,values),
                refresh:this.state.refresh+1
            })
        });
    };
    transformData=(data)=>{
        if(!data){
            return []
        }
        data.id=data.appkey;
        return [data]
    }


    render() {
        const {getFieldDecorator} = this.props.form;
        return(
            <SaasModal visible={this.props.visible} handleCancel={this.props.handleCancel} title={'添加权限'}>
                <form form={this.props.form}>
                    <Row gutter={16}>
                        <Col xl={5}>
                            <FormItem
                            >
                                {getFieldDecorator('appkey')(
                                    <Input placeholder={'请输入Appkey'}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4}>
                            <FormItem
                            
                            >
                                <Button style={{marginRight:4}} type="primary" htmlType="submit" onClick={this.handleSubmit}>{'搜索'}</Button>
                            </FormItem>
                        </Col>
                    </Row>
                </form>
                <Grid className={'sc-table'} transformData={this.transformData} noFirstFech={true} columns={this.columns2} fetchData={()=>{return EVCSDetails(this.state.params)}} refresh={this.state.refresh}/>
            </SaasModal>
        )
    }
}
sevenModal = createForm()(sevenModal);
export default sevenModal;